//公用js
//校验值为空
function isEmpty(value)
{
    if(null == value || "" == value || undefined == value)
    {
        return true;
    }
    return false;
}

//检查开始时间和结束时间是否正确
function checkQueryTime()
{
    var lowTime = $('#lowTime').val();
    var topTime = $('#topTime').val();
    var isSuccess = true;
    if(lowTime != '' || topTime != ''){
        if(lowTime != '' && new Date(Date.parse(lowTime.replace(/-/g,"/"))) >= new Date())
        {
            layer.alert("起始日期不可为未来时间");
            $('#lowTime').val("");
            isSuccess = false;
        }
        
        if(topTime != '' && new Date(Date.parse(topTime.replace(/-/g,"/"))) > new Date()){
            layer.alert("最后日期不可为未来时间");
            $('#topTime').val("");
            isSuccess = false;
        }
        if(lowTime != '' && topTime != '' && new Date(Date.parse(lowTime.replace(/-/g,"/"))) > new Date(Date.parse(topTime.replace(/-/g,"/")))){
            layer.alert("起始时间必须早于结束时间");
            $('#topTime').val("");
            isSuccess = false;
        }
    }
    return isSuccess;
}

//校验查询金额，模糊查询只允许输入整数
function checkQueryMoney(obj)
{
    var reg = /^(1|[1-9][0-9]*)$/;
    if(!reg.test($(obj).val()))
    {
        $(obj).val('');
    }
    else if($(obj).val().length > 8)  //限制输入八位
    {
    	$(obj).val($(obj).val().substring(0,8));
    }
}

//清除非数字输入
function clearNoNum(obj){   
	obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
	obj.value = obj.value.replace(/^\./g,"");  //验证第一个字符是数字而不是. 
	obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
	obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
}

//清除非整数输入
function clearNoInteger(obj){
	obj.value=obj.value.replace(/\D/g,"");
}

// 删除左右两端的空格
function trim(str) { 
	return str.replace(/(^\s*)|(\s*$)/g, "");
}

//校验页面参数输入是否正确
function isValidQueryParam()
{
    var isValid = true;
    
    //校验时间
    if(!checkQueryTime())
    {
        isValid = false;
    }
    return isValid;
}

//校验URL
function checkURL(URL)
{
    var str=URL;
    //下面的代码中应用了转义字符"\"输出一个字符"/"
    var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/; 
    var objExp=new RegExp(Expression);
    if(objExp.test(str)==true)
    {
       return true;
    }
    else
    {
       return false;
    }
}
//判断是否以指定字符串结束
function endWith(all,str){
	if(str==null||str==""||all.length==0||str.length>all.length)
	  return false;
	if(all.substring(all.length-str.length)==str)
	  return true;
	else
	  return false;
	return true;
}
//获取上传文件的文件名
function getFileName(path){
	var pos1 = path.lastIndexOf('/');
	var pos2 = path.lastIndexOf('\\');
	var pos  = Math.max(pos1, pos2);
	if( pos<0 )
	return path;
	else
	return path.substring(pos+1);
}

function keyDownQuery(e) {   
    // 兼容FF和IE和Opera    
    var theEvent = e || window.event;    
    var code = theEvent.keyCode || theEvent.which || theEvent.charCode;    
    if (code == 13) {    
    	var id = document.forms[0].id;
    	if(id == "queryCustomerInfo")
    	{
    		queryCustomerInfo();
    	}
    	else if(id == "queryMoneyRecord")
    	{
    		queryMoneyRecord();
    	}
    	else if(id == "queryProfitRecord")
    	{
    		queryProfitRecord();
    	}
    	else if(id == "queryFixedInvestRecord")
    	{
    		queryFixedInvestProject();
    	}
    	else if(id == "queryFixedInvestBargainRecord")
    	{
    		queryFixedInvestProjectBargin();
    	}
    	else if(id == "queryFixedInvestRecord")
    	{
    		queryFixedInvestProject();
    	}
    	else if(id == "queryWithdrawRecord")
    	{
    		queryWithdrawRecord();
    	}
    	else if(id == "queryRechargeRecord")
    	{
    		queryRechargeRecord();
    	}
    	else if(id == "queryRiskWithdrawRecord")
    	{
    		queryRiskWithdrawRecord();
    	}
    	else if(id == "queryFixedInvestCenterRecord")
    	{
    		queryFixedInvestRecord();
    	}
    	else if(id == "adaddForm")
    	{
    		submitForm(1);
    	}
    	else if(id == "adeditForm")
    	{
    		submitForm(2);
    	}
    	else if(id == "huixineditForm")
    	{
    		submitForm(2);
    	}
    	else if(id == "huixinaddForm")
    	{
    		submitForm(1);
    	}
    	else if(id == "queryPayOrderRecord")
    	{
    		queryPayOrderRecord();
    	}
    	else if(id == "queryLoginLog")
    	{
    		queryLoginLog();
    	}
    	else if(id == "queryOperaterLog")
    	{
    		queryOperaterLog();
    	}
    	else if(id == "queryUserBankRecord")
    	{
    		queryUserBankRecord();
    	}
    	else if(id == "querySystemParampage")
    	{
    		querySystemParampage();
    	}
    	else if(id == "querySystemCodeRecord")
    	{
    		querySystemCodeRecord();
    	}
    	else if(id == "queryHKBProfitRecord")
    	{
    		queryHKBProfitRecord();
    	}
    	
        return false;    
    }    
    return true;    
}

function exit() {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1,
        //month
        "d+": this.getDate(),
        //day
        "h+": this.getHours(),
        //hour
        "m+": this.getMinutes(),
        //minute
        "s+": this.getSeconds(),
        //second
        "q+": Math.floor((this.getMonth() + 3) / 3),
        //quarter
        "S": this.getMilliseconds() //millisecond
    }
    if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o) if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    return format;
}